package com.global.college.views;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.global.college.R;
import com.global.college.data.inner.BannerBean;
import com.global.college.ui.banner.OnBannerClickListener;

/**
 * TinyHung@Outlook.com
 * 2019/4/8
 */

public class TransformerMoiveItem extends FrameLayout {

    private ImageView mRoundImageView;

    public TransformerMoiveItem(@NonNull Context context) {
        this(context,null);
    }

    public TransformerMoiveItem(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        View.inflate(context, R.layout.video_pager_item,this);
    }

    public void setData(BannerBean data,OnBannerClickListener listener) {
        if(null!=data){
//            TextView tvDurtion = (TextView) findViewById(R.id.music_tr_item_durtion);
//            tvDurtion.setText(MusicUtils.getInstance().stringForAudioTime(data.getDuration()*1000));
//            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//                findViewById(R.id.view_root_item).setOutlineProvider(
//                        new VideoTextrueProvider(CommonUtils.dpToPxInt(CollegeApplication.getContext(),8f)));
//            }
            mRoundImageView = (ImageView) findViewById(R.id.music_tr_item_cover);
            Glide.with(getContext())
                    .load(data.getImgId())
                    .into(mRoundImageView);
            this.setTag(data);
            this.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(null!=view.getTag()){
                        BannerBean bean = (BannerBean) view.getTag();
//                        if (!StringUtils.isEmpty(bean.getTrainId())){
                            listener.onBannerClick(bean.getTrainId());
//                            Intent intent=new Intent(getContext().getApplicationContext(), train.class);
//                            intent.putExtra(VideoConstants.KEY_VIDEO_PARAMS,videoParams);
//                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                            getContext().getApplicationContext().startActivity(intent);
//                        }
                    }
                }
            });
        }
    }

    public void onDestroy() {
        if(null!=mRoundImageView){
            mRoundImageView.setImageResource(0);
            mRoundImageView=null;
        }
    }
}